package com.bigdata.quality.config.converter;

import java.util.HashMap;
import java.util.Map;

public class PGColumnTypeConverter implements ColumnTypeConverter {
  public static final PGColumnTypeConverter instance = new PGColumnTypeConverter();

  @Override
  public Map<String, String> toFlinkColumnTypeMap() {
    Map<String, String> columnTypeMap = new HashMap<>();

    columnTypeMap.put("decimal", "decimal(38,2)");
    columnTypeMap.put("boolean", "boolean");
    columnTypeMap.put("date", "date");
    columnTypeMap.put("time", "time(6)");
    columnTypeMap.put("timestamp", "timestamp(6)");
    columnTypeMap.put("char", "string");
    columnTypeMap.put("character", "string");
    columnTypeMap.put("varchar", "string");
    columnTypeMap.put("character varying", "string");
    columnTypeMap.put("text", "string");
    columnTypeMap.put("bytea", "bytes");
    columnTypeMap.put("array", "array");
    columnTypeMap.put("int4", "int");
    columnTypeMap.put("int8", "bigint");
    columnTypeMap.put("bpchar", "char(2147483647)");
    columnTypeMap.put("name", "string");
    columnTypeMap.put("time with time zone", "string");
    columnTypeMap.put("timestamp with time zone", "timestamp_ltz(6)");
    columnTypeMap.put("interval", "string");
    columnTypeMap.put("cidr", "string");
    columnTypeMap.put("inet", "string");
    columnTypeMap.put("macaddr", "string");
    columnTypeMap.put("int4range", "string");
    columnTypeMap.put("tsvector", "string");
    columnTypeMap.put("bit", "string");
    columnTypeMap.put("point", "string");
    columnTypeMap.put("line", "string");
    columnTypeMap.put("lseg", "string");
    columnTypeMap.put("box", "string");
    columnTypeMap.put("path", "string");
    columnTypeMap.put("polygon", "string");
    columnTypeMap.put("circle", "string");
    columnTypeMap.put("macaddr8", "string");
    columnTypeMap.put("varying", "string");
    columnTypeMap.put("tsquery", "string");
    columnTypeMap.put("uuid", "string");
    columnTypeMap.put("xml", "string");
    columnTypeMap.put("json", "string");
    columnTypeMap.put("bool", "boolean");
    columnTypeMap.put("timestamptz", "timestamp(6)");
    columnTypeMap.put("timetz", "time(6)");
    columnTypeMap.put("_int4", "string");

    return columnTypeMap;
  }

  @Override
  public String convertColumnType(Map<String, String> flinkColumnTypeMap, String sourceColumnType) {
    return ColumnTypeConverter.super.convertColumnType(flinkColumnTypeMap, sourceColumnType);
  }
}
